package com.qqclient.view;

import com.service.FileClientService;
import com.service.MessageClientService;
import com.service.UserClientService;
import com.utils.Utility;

import java.util.Scanner;

/**
 * 客户端菜单界面
 */
public class QQView {
    public static void main(String[] args) {
        new QQView().mainMenu();
        System.out.println("客户端已退出系统");
    }
 private boolean loop=true;//控制菜单显示
    private int key=0;//客户输入
    private MessageClientService messageClientService=new MessageClientService();//私聊/群聊 等消息处理
    private FileClientService fileClientService=new FileClientService();//文件消息
    private UserClientService userClientService=new UserClientService();//客户端业务处理:用户登录验证/注册等

    //主菜单
    public void mainMenu(){
        Scanner scanner = new Scanner(System.in);
        do{
            System.out.println("=======欢迎登录网络通信系统=========");
            System.out.println("\t\t1.登录");
            System.out.println("\t\t9.退出系统");
            System.out.print("请输入你的选择:");
            key=scanner.nextInt();

            switch(key){
                case 1://验证登录阶段
                    System.out.println("=======欢迎登录网络通信系统=========");
                    System.out.print("请输入用户名:");
                    String id=scanner.next();
                    System.out.print("请输入密    码:");
                    String password=scanner.next();
                    //验证密码阶段
                    //先省略
                    if(userClientService.checkUser(id,password)){//验证成功.进入二级菜单
                        System.out.println("=======欢迎" + id + "成功登录========");
                        do {
                            System.out.println("\n=======网络通信系统二级菜单("+id+"用户)=========");
                            System.out.println("\t\t1.显示所有在线客户");
                            System.out.println("\t\t2.群发消息");
                            System.out.println("\t\t3.私聊消息");
                            System.out.println("\t\t4.发送文件");//视屏,图片...
                            System.out.println("\t\t9.退出登录");
                            System.out.print("请输入你的选择:");
                            key=scanner.nextInt();

                            switch(key){
                                case 1:
                                   // System.out.println("\t\t1.显示所有在线客户");
                                    userClientService.onlineFriendList();
                                    break;
                                case 2:
                                   // System.out.println("\t\t2.群发消息");
                                    System.out.print("请输入要发送的内容:");
                                    String contentTo_all=Utility.readString(100);
                                    messageClientService.sendToAll(id,contentTo_all);
                                    break;
                                case 3:
                                    //System.out.println("\t\t3.私聊消息");
                                    System.out.print("请输入要私聊的用户:");
                                    String receive=Utility.readString(50);
                                    System.out.print("请输入要发送的内容:");
                                    String content=Utility.readString(100);
                                    messageClientService.sendToOne(id,receive,content);
                                    break;
                                case 4:
                                  //  System.out.println("\t\t4.发送文件");
                                    System.out.print("请输入要发送文件给谁: ");
                                    String receiver= Utility.readString(50);
                                    System.out.print("请输入文件所在路径: ");
                                    String src=Utility.readString(100);
                                    System.out.print("请输入要将文件发送至对方哪个目录: ");
                                    String dest=Utility.readString(100);
                                    fileClientService.sendToOne(src,dest,id,receiver);
                                    break;
                                case 9:
                                    loop=false;
                                    userClientService.logout();
                                    break;
                                default:
                                    System.out.println("出错了!请重新输入");
                                    break;

                            }
                        }while(loop);
                    }
                    else{//登录失败
                        System.out.println("======登录失败=========");
                    }
                    break;
                case 9:
                    loop=false;
                    break;
                default:
                    System.out.println("出错了!请重新输入");
                    break;
            }
        }while(loop);
    }
}
